<template>
    <div style="overflow: hidden;">
        <el-form v-loading="loadings" ref="ruleFormRef" :disabled="props.title == '查看招聘职位'" :model="state.ruleForm"
            :rules="rules" label-width="120px" :size="formSize" status-icon label-position="top">
            <div class="flex jcsb aic">
                <el-form-item class="formitem" label="职位名称" prop="positionName">
                    <el-input v-model="state.ruleForm.positionName" placeholder="请输入职位名称" />
                </el-form-item>
                <el-form-item label="招聘项目类别" prop="positionType" class="formitem">
                    <el-select v-model="state.ruleForm.positionType" placeholder="请选择招聘项目类别">
                        <el-option v-for="item in state.options1" :key="item.dictValue" :label="item.dictLabel"
                            :value="item.dictValue" />
                    </el-select>
                </el-form-item>
            </div>
            <div class="flex jcsb aic">
                <el-form-item label="薪资范围" prop="salaryStart" class="formitem">
                    <div class="flex aic jcsb">
                        <el-input v-model="state.ruleForm.salaryStart" @input="clearNoNum(state.ruleForm.salaryStart,0)"
                            @blur="salaryAbout" placeholder="薪资" class="input-with-select" style="width: 90px" />
                        <span style="margin: 0 3px;">-</span>
                        <el-input v-model="state.ruleForm.salaryEnd" @input="clearNoNum(state.ruleForm.salaryEnd,1)"
                            placeholder="薪资" @blur="salaryAbout" class="input-with-select" style="width: 165px">
                            <template #append>
                                <el-select disabled v-model="state.ruleForm.salaryUnit" placeholder="单位"
                                    style="width: 95px">
                                    <el-option label="K" value="K" />
                                    <!-- <el-option label="W" value="W" /> -->
                                </el-select>
                            </template>
                        </el-input>
                        <span style="margin: 0 3px;">x</span>
                        <el-input v-model="state.ruleForm.salaryRange" style="width: 135px" placeholder=""
                            class="input-with-select">
                            <template #append> 月</template>
                        </el-input>
                    </div>
                </el-form-item>
                <el-form-item label="应聘部门" prop="deptId" class="formitem">
                    <el-cascader v-model="state.ruleForm.deptId" style="width: 100%" clearable placeholder="请选择应聘部门"
                        :options="state.options" :props="props1" />
                </el-form-item>
            </div>
            <div class="flex jcsb aic">
                <el-form-item label="职位分类" prop="positionClassify" class="formitem">
                    <el-select v-model="state.ruleForm.positionClassify" placeholder="请选择职位分类">
                        <el-option v-for="item in state.options11" :key="item.dictValue" :label="item.dictLabel"
                            :value="item.dictValue" />
                    </el-select>
                </el-form-item>
                <el-form-item label="是否应急职位" prop="urgentPosition" class="formitem">
                    <el-select v-model="state.ruleForm.urgentPosition" clearable placeholder="请选择是否应急职位">
                        <el-option v-for="item in state.options15" :key="item.dictValue" :label="item.dictLabel"
                            :value="item.dictValue" />
                    </el-select>
                </el-form-item>
            </div>
            <div class="flex jcsb aic">
                <el-form-item label="学历要求" prop="educationRequirements" class="formitem">
                    <el-select v-model="state.ruleForm.educationRequirements" clearable placeholder="请选择学历">
                        <el-option v-for="item in state.options4" :key="item.dictValue" :label="item.dictLabel"
                            :value="item.dictValue" />
                    </el-select>
                </el-form-item>
                <el-form-item label="是否要求全日制" prop="" class="formitem">
                    <el-checkbox v-model="state.ruleForm.isFullTimeEducation" label="是否要求全日制" size="large" />
                </el-form-item>

            </div>
            <div class="flex jcsb aic">
                <el-form-item label="年限要求" prop="requirementsYears" class="formitem">
                    <el-select v-model="state.ruleForm.requirementsYears" placeholder="请选择年限要求">
                        <el-option v-for="item in state.options5" :key="item.dictValue" :label="item.dictLabel"
                            :value="item.dictValue" />
                    </el-select>
                </el-form-item>
                <el-form-item label="招聘截至日期" prop="recruitmentDeadline" class="formitem">
                    <el-date-picker type="datetime" v-model="state.ruleForm.recruitmentDeadline"
                        format="YYYY-MM-DD HH:mm" value-format="YYYY-MM-DD HH:mm:ss" label="" placeholder="招聘截至日期"
                        style="width: 100%" />
                </el-form-item>
            </div>
            <div class="flex jcsb aic">
                <el-form-item label="年龄要求" prop="ageRequirementsEnd" class="formitem">
                    <div class="flex aic jcsb">
                        <el-input-number style="width: 48%;" min="0" v-model="state.ruleForm.ageRequirementsStart"
                            placeholder="请输入年龄下限" @blur="ageAbout" />
                        <span>-</span>
                        <el-input-number @blur="ageAbout"  style="width: 48%;" :min="state.ruleForm.ageRequirementsStart"
                            v-model="state.ruleForm.ageRequirementsEnd" placeholder="请输入年龄上限" />
                    </div>
                </el-form-item>
                <el-form-item label="同一应聘部门是否能投递多个岗位" prop="" class="formitem">
                    <el-select v-model="state.ruleForm.multipleDeliveries" clearable placeholder="请选择">
                        <el-option v-for="item in state.options3" :key="item.dictValue" :label="item.dictLabel"
                            :value="item.dictValue" />
                    </el-select>
                </el-form-item>
            </div>
            <div class="flex jcsb aic">
                <el-form-item class="formitem" label="政治面貌" prop="politicalStatus">
                    <el-select v-model="state.ruleForm.politicalStatus" clearable placeholder="请选择政治面貌">
                        <el-option v-for="item in state.options6" :key="item.dictValue" :label="item.dictLabel"
                            :value="item.dictValue" />
                    </el-select>
                </el-form-item>
                <el-form-item label="到岗时间" prop="arrivalTime" class="formitem">
                    <el-select v-model="state.ruleForm.arrivalTime" placeholder="请选择到岗时间">
                        <el-option v-for="item in state.options7" :key="item.dictValue" :label="item.dictLabel"
                            :value="item.dictValue" />
                    </el-select>
                </el-form-item>
            </div>
            <div class="flex jcsb aic">
                <el-form-item label="性别要求" prop="genderRequirements" class="formitem">
                    <el-select v-model="state.ruleForm.genderRequirements" placeholder="请选择性别">
                        <el-option v-for="item in state.options8" :key="item.dictValue" :label="item.dictLabel"
                            :value="item.dictValue" />
                    </el-select>
                </el-form-item>
                <el-form-item prop="" class="formitem">
                    <template #label>
                        <span>自动放弃笔试的时间</span>
                        <el-popover placement="top-start" title="提示" :width="200" trigger="hover"
                            content="人选进入待笔试流程，需确认是否参加笔试。若未确认，系统将按设定时间自动放弃笔试。">
                            <template #reference>
                                <el-icon>
                                    <QuestionFilled />
                                </el-icon>
                            </template>
                        </el-popover>
                    </template>
                    <el-select v-model="state.ruleForm.giveUpTime" clearable placeholder="请选择自动放弃笔试">
                        <el-option v-for="item in state.options16" :key="item.dictValue" :label="item.dictLabel"
                            :value="item.dictValue" />
                    </el-select>
                </el-form-item>
            </div>
            <div class="flex jcsb aic">
                <el-form-item label="工作性质" prop="positionNature" class="formitem">
                    <el-select v-model="state.ruleForm.positionNature" placeholder="请选择工作性质">
                        <el-option v-for="item in state.options2" :key="item.dictValue" :label="item.dictLabel"
                            :value="item.dictValue" />
                    </el-select>
                </el-form-item>
                <el-form-item label="福利待遇" prop="welfareTreatment" class="formitem">
                    <el-select v-model="state.ruleForm.welfareTreatment" multiple collapse-tags placeholder="请选择福利待遇">
                        <el-option v-for="item in state.options9" :key="item.dictValue" :label="item.dictLabel"
                            :value="item.dictValue" />
                    </el-select>
                </el-form-item>
            </div>
            <div class="flex jcsb aic">
                <el-form-item label="" prop="registrationFormTemplateId" class="formitem" v-if="false">
                    <template #label>
                        <span>应聘报名报模板</span>
                        <el-popover placement="top-start" title="提示" :width="200" trigger="hover"
                            content="企业可自定义应聘报名表以符合招聘要求。在发布职位时选择对应报名表，应聘者需另外填写该报名表后方可投递。">
                            <template #reference>
                                <el-icon>
                                    <QuestionFilled />
                                </el-icon>
                            </template>
                        </el-popover>
                    </template>
                    <el-select v-model="state.ruleForm.registrationFormTemplateId" clearable placeholder="请选择应聘报名表">
                        <el-option :label="item.templateName" :value="item.id" v-for="(item, index) in state.options10"
                            :key="index" />
                    </el-select>
                </el-form-item>
                <el-form-item label="" prop="isShowLogs" class="formitem">
                    <template #label>
                        <span>是否隐藏应聘轨迹</span>
                        <el-popover placement="top-start" title="提示" :width="200" trigger="hover"
                            content="应聘轨迹图显示应聘者的投递状态，实时同步到应聘端。若选择隐藏，应聘者将无法查看相关流程信息。">
                            <template #reference>
                                <el-icon>
                                    <QuestionFilled />
                                </el-icon>
                            </template>
                        </el-popover>
                    </template>
                    <el-select v-model="state.ruleForm.isShowLogs" clearable placeholder="是否隐藏应聘轨迹">
                        <el-option :label="item.dictLabel" :value="item.dictValue" v-for="item in state.options3"
                            :key="item.dictValue" />
                    </el-select>
                </el-form-item>
                <!-- <el-form-item label="应聘地址" prop="registrationFormTemplateId" class="formitem">
                    <el-select v-model="state.ruleForm.registrationFormTemplateId" placeholder="请选择应聘报名表">
                        <el-option label="Zone one" value="shanghai" />
                        <el-option label="Zone two" value="beijing" />
                    </el-select>
                </el-form-item> -->
                <el-form-item label="招聘人数" prop="recruitmentNumber" class="formitem">
                    <el-input-number min="0" style="width: 100%;" v-model="state.ruleForm.recruitmentNumber"
                        placeholder="请输入招聘人数" />
                </el-form-item>
                <!-- <el-form-item label="是否全日制" prop="" class="formitem">
                    <el-checkbox v-model="state.ruleForm.isFullTimeEducation"  label="是否全日制" size="large" />
                </el-form-item> -->
            </div>
            <div class="flex jcsb aic">
                <el-form-item label="职位性质" prop="workNature" class="formitem">
                    <el-select v-model="state.ruleForm.workNature" placeholder="请选择职位性质">
                        <el-option v-for="item in state.options17" :key="item.dictValue" :label="item.dictLabel"
                            :value="item.dictValue" />
                    </el-select>
                </el-form-item>
            </div>
            <div class="flex jcsb aic" v-if="false">
                <el-form-item label="是否全日制" prop="" class="formitem">
                    <el-checkbox v-model="state.ruleForm.isFullTimeEducation" label="是否全日制" size="large" />
                </el-form-item>
            </div>
            <el-form-item label="应聘详细地址" prop="applicationAddress">
                <el-input v-model="state.ruleForm.applicationAddress" placeholder="请输入应聘详细地址" />
            </el-form-item>
            <el-form-item label="职位描述" prop="positionDesc">
                <el-input v-model="state.ruleForm.positionDesc" :autosize="{ minRows: 2 }" type="textarea"
                    placeholder="请输入职位描述" />
            </el-form-item>
            <el-form-item label="简历匹配度配置" prop="resumeMatchingConfig" class="posit">
                <p class="posit-p">说明：勾选对应字段，若应聘人员满足该字段的职位要求以上则匹配度得1分</p>
                <el-checkbox-group v-model="state.ruleForm.resumeMatchingConfig">
                    <el-checkbox v-for="item in state.options12" :key="item.dictValue" :label="item.dictLabel"
                        :value="item.dictValue" />
                </el-checkbox-group>
            </el-form-item>
            <el-form-item label="系统初筛配置" prop="systemFirstConfig" class="posit">
                <p class="posit-p">说明：勾选对应字段，若应聘人员满足该字段的职位要求以上则匹配度得1分</p>
                <el-checkbox-group v-model="state.ruleForm.systemFirstConfig">
                    <el-checkbox v-for="item in state.options13" :key="item.dictValue" :label="item.dictLabel"
                        :value="item.dictValue" />

                </el-checkbox-group>
            </el-form-item>
            <el-form-item label="简历筛选流程配置" prop="resumeScreeningProcessConfig" class="posit">
                <p class="posit-p">说明：勾选对应字段，若应聘人员满足该字段的职位要求以上则匹配度得1分</p>
                <el-checkbox-group v-model="state.ruleForm.resumeScreeningProcessConfig">
                    <el-checkbox v-for="item in state.options14" :key="item.dictValue" :label="item.dictLabel"
                        :value="item.dictValue" />
                </el-checkbox-group>
            </el-form-item>
            <el-form-item style="margin-top: 16px;" class="flex jcc">
                <el-button type="primary" @click="submitForm(ruleFormRef)">
                    保存
                </el-button>
                <el-button @click="resetForm(ruleFormRef)">取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script lang="ts" setup>
import { ElButton, ElInput, ElMessage, ElMessageBox } from 'element-plus'
import { addpositionApi, editpositionApi } from "@/api/recruit/index"
import { formTemplateList } from "@/api/resume/index"
import { deptTreeList } from "@/api/organizational/index"
import { dictSect } from "@/utils/dictUnit"
import { reactive, ref, onMounted, watch } from 'vue'
import { Search, Plus, Refresh, Pointer, Star, QuestionFilled } from '@element-plus/icons-vue'
import type { FormInstance, FormRules } from 'element-plus'
const props1 = {
    checkStrictly: true,
    value: "id",
    label: "label",
    emitPath: false
}
const props = defineProps({
    data: {
        type: Object,
        default: () => { }
    },
    title: {
        type: String,
        default: () => ""
    }
})

const loading = ref(false)
const emit = defineEmits(['FormClick'])
const state = reactive({
    ruleForm: {} as any,
    options: [] as any,//应聘部门
    options1: [] as any,//招聘分类
    options2: [] as any,//职位分类
    options3: [] as any,//是否
    options4: [] as any,//学历
    options5: [] as any,//工作年限
    options6: [] as any,//政治面貌
    options7: [] as any,//到岗时间
    options8: [] as any,//性别
    options9: [] as any,//福利待遇
    options10: [] as any,//应聘报名表
    options11: [] as any,//职位分类
    options12: [] as any,//简历匹配度配置
    options13: [] as any,//系统初筛配置
    options14: [] as any,//简历筛选流程配置
    options15: [] as any,
    options16: [] as any,
    options17: [] as any,// 配置职位性质
})
// const props = defineProps({
//     FromData: {
//         type: Object,
//         default: () => {
//             return {}
//         }
//     }

// })
const clearNoNum = (val,number) => {
    if(number==0){
        state.ruleForm.salaryStart=state.ruleForm.salaryStart.replace(/^(-)*(\d+)\.(\d).*$/, '$1$2.$3') // 保留一位小数
        .replace(/[^\d.]/g, '') // 清除"数字和."以外的字符
        .replace(/^\./g, '') // 验证第一个字符是数字
        .replace(/\.{2,}/g, '.') //只保留第一个. 清除多余的
    }else{
        state.ruleForm.salaryEnd=state.ruleForm.salaryEnd.replace(/^(-)*(\d+)\.(\d).*$/, '$1$2.$3') // 保留一位小数
        .replace(/[^\d.]/g, '') // 清除"数字和."以外的字符
        .replace(/^\./g, '') // 验证第一个字符是数字
        .replace(/\.{2,}/g, '.') //只保留第一个. 清除多余的
    }
    
}
const info = async () => {
    state.options1 = dictSect("position_type")
    state.options2 = dictSect("position_nature")
    state.options3 = dictSect("sys_yes_no")
    state.options4 = dictSect("education")
    // state.options4 = [...[{ dictValue: "", dictLabel: "不限" }], ...dictSect("education")]
    state.options5 = dictSect("requirements_years")
    state.options6 = dictSect("political_outlook")
    // state.options6 =[...[{ dictValue: "", dictLabel: "不限" }], ...dictSect("political_outlook")]
    state.options7 = dictSect("arrival_time")
    state.options8 = dictSect("sys_user_sex")
    // state.options8 = [...[{ dictValue: "-1", dictLabel: "不限" }], ...dictSect("sys_user_sex")]
    state.options9 = dictSect("welfare_treatment")
    state.options11 = dictSect("position_classify")
    state.options12 = dictSect("resume_matching_config")
    state.options13 = dictSect("system_first_config")
    state.options15 = dictSect("sys_yes_no")
    state.options14 = dictSect("resume_screening_process_config")
    state.options14.sort(function (a, b) {
        if (a.dictSort < b.dictSort) {
            return -1;
        }
        if (a.dictSort > b.dictSort) {
            return 1;
        }

        // 年龄相同的情况下，按照 id 排序 

        return 0;
    });
    console.log("简历筛选排序：", state.options14);

    state.options16 = dictSect("give_up_time")
    state.options17 = dictSect("work_nature")
}


info()
interface RuleForm {
    workNature: string
    positionName: string
    positionType: string
    salaryStart: string
    deptId: string
    positionClassify: string
    educationRequirements: string
    recruitmentNumber: number
    requirementsYears: string
    recruitmentDeadline: string
    ageRequirementsEnd: number
    multipleDeliveries: string
    politicalStatus: string
    arrivalTime: string
    genderRequirements: string
    giveUpTime: string
    welfareTreatment: string
    positionNature: []
    registrationFormTemplateId: string
    applicationAddress: string
    positionDesc: string
    urgentPosition: string
    resumeScreeningProcessConfig:string
}
watch(() => props.data, (newValue: any) => {
    if (props.title == "新增招聘职位") {
        state.ruleForm = newValue
        state.ruleForm.salaryUnit = "K"
        // state.ruleForm.isFullTimeEducation = false
        // state.ruleForm.welfareTreatment=[] as any
    } else {
        // console.log(newValue);
        for (const key in newValue) {
            state.ruleForm[key] = newValue[key];
        }
        state.ruleForm.isFullTimeEducation = state.ruleForm.isFullTimeEducation == 1 ? true : false
        state.ruleForm.urgentPosition = state.ruleForm.urgentPosition.toString()
        state.ruleForm.multipleDeliveries = state.ruleForm.multipleDeliveries.toString()
        state.ruleForm.isShowLogs = state.ruleForm.isShowLogs.toString()
        state.ruleForm.welfareTreatment = stringFun2(state.ruleForm.welfareTreatment)
        state.ruleForm.resumeMatchingConfig = arrayFun2(state.ruleForm.resumeMatchingConfig, state.options12)
        state.ruleForm.systemFirstConfig = arrayFun2(state.ruleForm.systemFirstConfig, state.options13)
        state.ruleForm.resumeScreeningProcessConfig = arrayFun2(state.ruleForm.resumeScreeningProcessConfig, state.options14)
    }

}, { deep: true, immediate: true })
const ageAbout = () => {
    if (state.ruleForm.ageRequirementsStart > state.ruleForm.ageRequirementsEnd) {
        ElMessage({
            type: 'error',
            message: `开始年龄不能大于结束年龄！`,
        })
        state.ruleForm.ageRequirementsEnd = state.ruleForm.ageRequirementsStart
        return
    }
}
const salaryAbout = () => {
    if (state.ruleForm.salaryStart * 1 > state.ruleForm.salaryEnd * 1) {
        ElMessage({
            type: 'error',
            message: `最低薪资不能大于最高薪资！`,
        })
        state.ruleForm.salaryEnd = state.ruleForm.salaryStart
        return
    }
}
const formSize = ref('default')
const ruleFormRef = ref<FormInstance>()

const rules = reactive<FormRules<RuleForm>>({
    positionName: [
        { required: true, message: '请输入职位名称', trigger: 'blur' },
        { min: 1, max: 50, message: '请输入1~50个字符', trigger: 'blur' },
    ],
    positionType: [
        { required: true, message: '请选择招聘项目类别', trigger: 'blur' },
    ],
    salaryStart: [
        { required: true, message: '请输入薪资范畴', trigger: 'blur' },
    ],
    urgentPosition: [{ required: true, message: '请选择是否为紧急职位', trigger: 'blur' }],
    deptId: [{ required: true, message: '请选择部门', trigger: 'blur' }],
    positionClassify: [{ required: true, message: '请选择职位分类', trigger: 'blur' }],
    workNature: [{ required: true, message: '请选择职位性质', trigger: 'blur' }],
    educationRequirements: [{ required: true, message: '请选择学历', trigger: 'blur' }],
    recruitmentNumber: [{ required: true, message: '请输入招聘人数', trigger: 'blur' }],
    requirementsYears: [{ required: true, message: '请输入招聘人数', trigger: 'blur' }],
    recruitmentDeadline: [{ required: true, message: '请选择招聘截止日期', trigger: 'blur' }],
    ageRequirementsEnd: [{ required: true, message: '请输入年龄要求', trigger: 'blur' }],
    multipleDeliveries: [{ required: true, message: '此选项为必选项', trigger: 'blur' }],
    politicalStatus: [{ required: true, message: '请选择政治面貌', trigger: 'blur' }],
    arrivalTime: [{ required: true, message: '请选择到岗时间', trigger: 'blur' }],
    genderRequirements: [{ required: true, message: '请选择性别', trigger: 'blur' }],
    giveUpTime: [{ required: true, message: '请选择自动放弃笔试的时间', trigger: 'blur' }],
    welfareTreatment: [{ type: "array", required: true, message: '请选择福利待遇', trigger: 'change' }],
    positionNature: [{ required: true, message: '请选择工作性质', trigger: 'blur' }],
    // registrationFormTemplateId: [{ required: true, message: '请选择应聘报名表模板', trigger: 'blur' }],
    applicationAddress: [{ required: true, message: '请输入应聘详细地址', trigger: 'blur' }],
    positionDesc: [{ required: true, message: '请输入职位描述', trigger: 'blur' }],
    resumeScreeningProcessConfig:[{ required: true, message: '请勾选简历筛选流程配置', trigger: 'blur' }],


})
const loadings = ref(false)
const submitForm = async (formEl: FormInstance | undefined) => {
    if (!formEl) return
    await formEl.validate((valid, fields) => {
        if (valid) {
            console.log('submit!')
            let obj = {}
            for (const key in state.ruleForm) {
                obj[key] = state.ruleForm[key];
            }
            obj.isFullTimeEducation = state.ruleForm.isFullTimeEducation ? 1 : 0
            obj.welfareTreatment = stringFun(obj.welfareTreatment)
            obj.resumeMatchingConfig = arrayFun(obj.resumeMatchingConfig, state.options12)
            obj.systemFirstConfig = arrayFun(obj.systemFirstConfig, state.options13)
            obj.resumeScreeningProcessConfig = arrayFun(obj.resumeScreeningProcessConfig, state.options14)
            // obj.registrationFormTemplateId=obj.registrationFormTemplateId?obj.registrationFormTemplateId:null
            console.log("数据：", obj);
            if (props.title == "新增招聘职位") {
                addpositionApi(obj).then((res: any) => {
                    ElMessage({
                        type: 'success',
                        message: `${res.msg}`,
                    })
                    emit("FormClick", 0)
                    dialogVisible1.value = false
                    loadings.value = false
                }).catch((res: any) => {
                    ElMessage({
                        type: 'error',
                        message: `${res.msg}`,
                    })
                    loadings.value = false
                })
            } else {
                ElMessageBox.confirm('确认修改该职位，修改成功后重新进入待审核状态！', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    // inputPattern:,
                    draggable: true,
                    type: 'warning',
                }).then(() => {
                    editpositionApi(obj).then((res: any) => {
                        ElMessage({
                            type: 'success',
                            message: `${res.msg}`,
                        })
                        emit("FormClick", 0)
                        loadings.value = false
                        dialogVisible1.value = false
                    }).catch((res: any) => {
                        ElMessage({
                            type: 'error',
                            message: `${res.msg}`,
                        })
                        loadings.value = false
                    })
                }).catch(() => {
                    ElMessage({
                        type: 'info',
                        message: '取消操作',
                    })
                })

            }
        } else {
            console.log('error submit!', fields)
        }
    })
}
function stringFun(array) {
    let string = ""
    array.forEach(element => {
        if (string == "") {
            string = element
        } else {
            string = string + "," + element
        }

    });
    return string
}
function arrayFun(data, datas) {
    let string = ""
    if (!data || data.length == 0) {
        return string
    }
    data.forEach(element => {
        datas.forEach(elements => {
            if (element == elements.dictLabel) {
                if (string == "") {
                    string = elements.dictValue
                } else {
                    string = string + "," + elements.dictValue
                }
            }
        })
    })
    return string
}
function stringFun2(str) {
    console.log("str");

    let arr = []
    if (str) {
        arr = str.split(",");
    }
    return arr
}
function arrayFun2(data, datas) {
    console.log(datas);
    let arr = data.split(",");
    let array = []
    arr.forEach(element => {
        datas.forEach(elements => {
            // console.log(elements);
            if (element == elements.dictValue) {
                array.push(elements.dictLabel)
            }
        })
    })
    // console.log(array);

    return array
}
const resetForm = (formEl: FormInstance | undefined) => {
    emit("FormClick", 1)
    if (!formEl) return
    formEl.resetFields()
}

const deptTreeListApi = async () => {
    await deptTreeList().then(res => {
        state.options = res.data.tree
    })
}
deptTreeListApi()
const formTemplateListApi = async () => {
    await formTemplateList({ pageNum: 1, pageSize: 10000 }).then((res: any) => {
        state.options10 = res.rows
    })
}
formTemplateListApi()
</script>
<style lang="less"></style>
<style lang="less" scoped>
.ruleFrom {
    .el-form-item {
        width: 400px;
    }
}

.formitem {
    width: 320px;

    .el-input {
        width: 100%;
    }

    .el-select {
        width: 100%;
    }
}

.posit {
    position: relative;

    .posit-p {
        position: absolute;
        top: -35px;
        left: 200px;
        font-size: 12px;
        color: #B5B9C8;
    }
}
</style>